package com.too.service;

import com.alicp.jetcache.anno.CachePenetrationProtect;
import com.alicp.jetcache.anno.CacheRefresh;
import com.alicp.jetcache.anno.Cached;
import com.too.domain.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * 用户逻辑
 *
 * @author ouyf
 * @date 2024/11/5 11:44
 * <p>
 * Copyright (c) Siemens Mobility TBDS 2024, All Rights Reserved, Confidential
 */
@Slf4j
@Service
public class UserService {

    @Cached(name = "userCache.", key = "#id", expire = 2)
    @CacheRefresh(refresh = 1500, stopRefreshAfterLastAccess = 3600, timeUnit = TimeUnit.MILLISECONDS)
    @CachePenetrationProtect
    public User getUserById(Integer id) {
        log.info("getUserById from db:{}", id);
        return User.builder().name("ouyf").age(24).address("shanghai").phone("12345678901").id(id).build();
    }
}
